'use strict';

var express = require('express'),
    morgan = require('morgan'),
    bodyParser = require('body-parser'),
    http = require('http');

// Initialize express
var app = express();

process.isDev = function () {
    return app.get('env') === 'development';
};
process.isProd = function () {
    return app.get('env') === 'production';
};

process.verb = function () {
    if (process.isDev()) {
        console.log.apply(this, arguments);
    }
};

// Dev logging
if (process.isDev()) {
    app.use(morgan('dev'));
}

// JSON support for body parsing
app.use(bodyParser.json());

// Body parser
app.use(bodyParser.urlencoded({extended: true}));

var jwt = require('./passport')(app);

// Initialize our routes
require('./route.js')(app, express, jwt);

var port = process.env.listenPort || 8080;
var ip = process.env.listenIp || '127.0.0.1';

app.listen(port, ip, function () {
    console.log('Simple Server listening on %d', port);
});

// Export express
module.exports = app;